/*
 * @(#)UserUpdateBean.java       2010-10-19
 *
 * Copyright（c）2010 北京云狐软件有限公司保留所有权利.
 */
package com.yunhoo.sys.bean;

import com.yunhoo.base.db.impl.PersonImpl;
import com.yunhoo.base.model.Person;
import com.yunhoo.cqq.util.StrUtil;
import com.yunhoo.sys.login.LoginInfo;
import com.yunhoo.sys.util.common.FacesUtils;
import com.yunhoo.sys.util.common.ToolKit;
import java.util.HashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 * 类
 * <code>UserUpdateBean</code>
 *
 * @author 胡开龙
 * @version 2010-10-19
 * @see java.lang.Class
 * @since jdk1.6
 */
@ManagedBean(name = "userPwdBean")
@ViewScoped
public class UserManageBean {

    private String oldPassword;
    private String newPassword;
    private String confPassword;
    private boolean showNewInput = false;
    private String wrongMass;
    private boolean showRight = false;

    public UserManageBean() {
    }

    public void confOldPwd() {
        LoginInfo login = (LoginInfo) FacesUtils.getSessionAttribute("loginInfo");
        if (login != null) {
            String cpsn_number = login.getPer().getCpsn_number();
            Person user = PersonImpl.queryByPerNumber(cpsn_number);
            if (user != null) {
                String password = user.getPwd();
                if (password.trim().equals(oldPassword)) {
                    showNewInput = true;
                    wrongMass = "";
                }
            }
        }
        if (showNewInput == false) {
            wrongMass = "密码错误请重新输入";
        }
    }

    public void confNewPwd() {
        if (StrUtil.isEmpty(newPassword, confPassword)) {
            if (newPassword.trim().equals(confPassword.trim())) {
                LoginInfo login = (LoginInfo) FacesUtils.getSessionAttribute("loginInfo");
                if (login != null) {
                    Map map = new HashMap();
                    Person user = login.getPer();
                    if (user != null) {
                        map.put("cpsn_number", user.getCpsn_number());
                        map.put("pwd", newPassword);
                        PersonImpl.usrUpdatePwd(map);//修改密码
                    }
                }
                showRight = true;
            }
        }
        if (showRight == false) {
            //wrongMass = "两次密码不能为空且必须一样";
            ToolKit.msgs_err("两次密码不能为空且必须一样");
        }

    }

    public void confBack() {
        showNewInput = false;
        showRight = false;
        wrongMass = "";

    }

    public boolean isShowRight() {
        return showRight;
    }

    public void setShowRight(boolean showRight) {
        this.showRight = showRight;
    }

    public String getWrongMass() {
        return wrongMass;
    }

    public void setWrongMass(String wrongMass) {
        this.wrongMass = wrongMass;
    }

    public String getConfPassword() {
        return confPassword;
    }

    public void setConfPassword(String confPassword) {
        this.confPassword = confPassword;
    }

    public String getNewPassword() {
        return newPassword;
    }

    public void setNewPassword(String newPassword) {
        this.newPassword = newPassword;
    }

    public String getOldPassword() {
        return oldPassword;
    }

    public void setOldPassword(String oldPassword) {
        this.oldPassword = oldPassword;
    }

    public boolean isShowNewInput() {
        return showNewInput;
    }

    public void setShowNewInput(boolean showNewInput) {
        this.showNewInput = showNewInput;
    }
}
